<?php
/**
 * Created by PhpStorm.
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/9/2 0002
 * Time: 10:50
 */

namespace Common\Model;
use Think\Model;

class WorkorderModel extends Model
{
    protected $_validate = [
        ['title', 'require', '请填写标题'],
        ['content', 'require', '请填写内容'],
        ['linktel', 'require', '请填写手机号'],

    ];
    //插入数据
    public function orderadd()
    {

        if(!$this->create()){
            $arr['state']='error';
            $arr['info']=$this->getError();
            return $arr;
      }else{
            if($_POST['wid'] =='' || !isset($_POST['wid']) ){
                $_POST['create_time']=time();
                if($this->add($_POST)){
                    $arr['state']='success';
                    $arr['info']='提交成功';
                }else{
                    $arr['state']='error';
                    $arr['info']='提交失败';
                }
                return $arr;

            }else{
                $wid=$_POST['wid'];
                $_POST['update_time']=time();
                $_POST['status']=0;
               if( $this->where("wid=%d",$wid)->save($_POST)){
                   $arr['state']='success';
                   $arr['info']='提交成功';
               }else{
                   $arr['state']='error';
                   $arr['info']='提交失败';
               }
                return $arr;
            }

        }

    }
    //工单列表
    public function lister()
    {
        $wap_userId=$_COOKIE['wap_userId'];
        $list=$this->alias("a")->field("a.*,b.nickname")
            ->join("sr_dealer_userinfo as b on a.formid=b.id")->where("a.formid=%d and a.status !=%d",[$wap_userId,-1])->select();
        return $list;
    }


}